<template>
  <div class="reportsBox">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <div id="box"></div>
    </el-card>
  </div>
</template>

<script>
import { getReports } from "../../api/index";
export default {
  data() {
    return {
      list: [],
      options: {
        title: {
          text: "用户来源",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      },
    };
  },
  mounted() {
    this.initChartsData();
  },
  methods: {
    async initChartsData() {
      let res = await getReports();
      console.log(res);
      let {
        data,
        meta: { msg, status },
      } = res;
      if (status != 200) return this.$message.error(msg);
      this.list = data; // 获取到的对象
      //   合并
      let newOptions = { ...this.options, ...data };
      this.initCharts(newOptions);
      console.log(newOptions)
    },
    initCharts(option) {
      var myChart = this.$echarts.init(document.getElementById("box"));
      myChart.setOption(option);
    },
  },
};
</script>

<style>
#box {
  width: 750px;
  height: 400px;
}
</style>